package com.android.porttallymansystem.ui.fragment

import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.android.porttallymansystem.R
import com.android.porttallymansystem.databinding.FragmentMessageBinding
import com.android.porttallymansystem.logic.Repository
import com.android.porttallymansystem.ui.activity.SystemMessageActivity
import com.android.porttallymansystem.ui.adapter.MessageAdapter
import kotlin.concurrent.thread

class MessageFragment : Fragment() {

    private lateinit var binding: FragmentMessageBinding

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding = FragmentMessageBinding.inflate(inflater, container, false)

        initMessage()

        setListener()

        return binding.root
    }

    private fun initMessage() {
        thread {
            binding.rvMessages.layoutManager = LinearLayoutManager(context)
            binding.rvMessages.adapter = MessageAdapter(Repository.getBriefMessage())
        }
    }

    private fun setListener() {
        binding.btSystemMessage.setOnClickListener {
            val intent = Intent(context, SystemMessageActivity::class.java)
            startActivity(intent)
        }
    }
}